// ================================================================================
// 		File: PartyJoinProcess.cs
// 		Desc: 
//  
// 		Called by:   
//               
// 		Auth: chenwenzhi（--）
// 		Date: 2015-12-28 23:59
// ================================================================================
// 		Change History
// ================================================================================
// 		Date:		Author:				Description:
// 		--------	--------			-------------------
//    
// ================================================================================
// --
// ================================================================================
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;

namespace ZHDJ.Data.Models.JoinParty
{
    /// <summary>
    /// 
    /// </summary>   
    public class PartyJoinProcess : EntityBase
    {
        #region 属性
        /// <summary>
        /// ProcessName
        /// </summary>
        [StringLength(128)]
        public string ProcessName { get; set; }

        /// <summary>
        /// StepNo
        /// </summary>
        public int StepNo { get; set; }

        /// <summary>
        /// BackToStepID
        /// </summary>
        [StringLength(128)]
        public string BackToStepID { get; set; }

        /// <summary>
        /// WorkPoint
        /// </summary>
        public string WorkPoint { get; set; }

        /// <summary>
        /// Description
        /// </summary>
        public string Description { get; set; }

        /// <summary>
        /// IsSendMassage
        /// </summary>
        public bool IsSendMassage { get; set; }

        #endregion

        public static DataSet GetGridData()
        {
            string sql = "select s.*,(select ProcessName from tblPartyJoinProcess p where s.BackToStepID=p.ID limit 1) BackToStepName from tblPartyJoinProcess s  where 1=1 ORDER BY StepNo ";

            return MySqlHelper.ExecuteDataSet(sql);
        }

        public static DataSet GetModelData(string ID)
        {
            string sql = "select * from tblPartyJoinProcess where 1=1 and id='" + ID + "'";
            return MySqlHelper.ExecuteDataSet(sql);
        }

        public static DataSet GetGirdData(string processName, string stepNo = "")
        {
            StringBuilder Sbsql = new StringBuilder();
            Sbsql.Append(@" select data.ID,data.BackToStepID,data.StepNo,data.ProcessName,
                                (SELECT a.ProcessName from tblPartyJoinProcess a where a.ID=data.BackToStepID) as BackToName from tblPartyJoinProcess data where 1=1 ");
            if (!string.IsNullOrEmpty(stepNo))
            {
                Sbsql.AppendFormat(" and stepNo<'{0}'", stepNo);
            }
            if (!string.IsNullOrEmpty(processName))
            {
                Sbsql.AppendFormat(" and ProcessName='{0}'", processName);
            }
            Sbsql.Append(" order by StepNo ");
            DataSet ds = MySqlHelper.ExecuteDataSet(Sbsql.ToString());
            return ds;
        }
        public static string GetCurrentStepNo(string CurrentID)
        {
            string sql = @"select * from tblPartyJoinProcess where ID='" + CurrentID + "'";
            DataSet ds = MySqlHelper.ExecuteDataSet(sql);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return ds.Tables[0].Rows[0]["StepNo"].ToString();
            }
            else return "";
        }
    }
}
